package com.hhs.storage.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.hhs.storage.bean.InputParam;
import com.hhs.storage.bean.Result;
import com.hhs.storage.bean.YymFl;
import com.hhs.storage.service.YymFlService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yuanjun
 * @since 2020-08-19
 */
@RestController
@RequestMapping("/do/yymfl")
@Slf4j
public class YymFlController {
    @Resource
    YymFlService  yymFlService;
    @RequestMapping(value = "getAll")
    public Map<String, Object> getAll(InputParam inputParam) {
        log.info("查询分类页信息");
        EntityWrapper ew = new EntityWrapper<YymFl>();
        ew.orderBy("type_",false);
        Page<YymFl> result = yymFlService.selectPage(new Page<YymFl>(inputParam.getPage(), inputParam.getSize()),ew);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("rows", result.getRecords());
        map.put("total",result.getTotal());
        return map;
    }

    @RequestMapping(value = "delete/{id}", method = RequestMethod.DELETE)
    public Map<String, Object> dele(@PathVariable("id") String id) {
        log.info("删除人员");
        yymFlService.delete(new EntityWrapper<YymFl>().eq("id_", id));
        return Result.sucJsonResp(null);
    }

    @RequestMapping(value = "save")
    public Map<String, Object> saveOrUpdate(YymFl fl){
        log.info("新增分类信息");
        boolean ins = yymFlService.insert(fl);
        if(ins==true){
            return Result.sucJsonResp(null);
        }
        return Result.failJsonResp("未知错误");
    }
}

